﻿Imports System.Diagnostics

Public Interface TestTime
    ReadOnly Property TempsExec(ByVal numTimer) As Double
    Sub StartTimer(ByVal numTimer As Integer)
    Sub StopTimer()
End Interface

Public Class TestTimeImpl
    Implements TestTime

    Private m_TempsExecution As Dictionary(Of Integer, Stopwatch)
    Private m_ActiveStopWatch As Stopwatch

    Public Sub New()
        m_TempsExecution = New Dictionary(Of Integer, Stopwatch)
    End Sub

    Public Sub StartTimer(ByVal numTimer As Integer) Implements TestTime.StartTimer
        If Not m_TempsExecution.ContainsKey(numTimer) Then
            m_TempsExecution.Add(numTimer, New Stopwatch)
        End If
        If Not m_ActiveStopWatch Is Nothing Then
            m_ActiveStopWatch.Stop()
        End If
        m_TempsExecution(numTimer).Start()
        m_ActiveStopWatch = m_TempsExecution(numTimer)
    End Sub

    Public Sub StopTimer() Implements TestTime.StopTimer
        If Not m_ActiveStopWatch Is Nothing Then
            m_ActiveStopWatch.Stop()
        End If
    End Sub

    Public ReadOnly Property TempsExec(ByVal numTimer As Object) As Double Implements TestTime.TempsExec
        Get
            If m_TempsExecution.ContainsKey(numTimer) Then
                Return m_TempsExecution(numTimer).ElapsedMilliseconds
            Else
                Return 0
            End If
        End Get
    End Property
End Class
